# Copyright 2024 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

load("@rules_python//python:defs.bzl", "py_library")
load("//pw_build:python.bzl", "pw_py_binary", "pw_py_test")

py_library(
    name = "pw_emu",
    srcs = [
        "pw_emu/__init__.py",
        "pw_emu/__main__.py",
        "pw_emu/core.py",
        "pw_emu/frontend.py",
        "pw_emu/pigweed_emulators.py",
        "pw_emu/qemu.py",
        "pw_emu/renode.py",
    ],
    imports = ["."],
    visibility = ["//visibility:public"],
    deps = [
        "//pw_env_setup/py:pw_env_setup",
        "@pigweed_python_packages//psutil",
        "@pigweed_python_packages//pyserial",
    ],
)

pw_py_test(
    name = "cli_test",
    srcs = [
        "tests/cli_test.py",
    ],
    imports = ["."],
    main = "tests/cli_test.py",
    # TODO: b/348410988 - Test relies on PW_ROOT
    tags = ["manual"],
    deps = [
        ":config_helper",
        ":mock_emu_frontend",
        ":pw_emu",
    ],
)

pw_py_test(
    name = "core_test",
    srcs = [
        "tests/core_test.py",
    ],
    data = [":mock_emu"],
    main = "tests/core_test.py",
    # TODO: b/348410988 - Test relies on gdb in environment
    tags = ["manual"],
    deps = [
        ":config_helper",
        ":mock_emu_frontend",
        ":pw_emu",
    ],
)

pw_py_test(
    name = "frontend_test",
    srcs = [
        "tests/frontend_test.py",
    ],
    data = [":mock_emu"],
    main = "tests/frontend_test.py",
    # TODO: b/348410988 - Test relies on gdb in environment
    tags = ["manual"],
    deps = [
        ":config_helper",
        ":mock_emu_frontend",
        ":pw_emu",
    ],
)

pw_py_test(
    name = "qemu_test",
    srcs = [
        "tests/qemu_test.py",
    ],
    data = [":mock_emu"],
    main = "tests/qemu_test.py",
    # TODO: b/348410988 - Test relies on PW_ROOT
    tags = ["manual"],
    deps = [
        ":config_helper",
        ":mock_emu_frontend",
        ":pw_emu",
    ],
)

pw_py_test(
    name = "renode_test",
    srcs = [
        "tests/renode_test.py",
    ],
    data = [":mock_emu"],
    main = "tests/renode_test.py",
    # TODO: b/348410988 - Test relies on PW_ROOT
    tags = ["manual"],
    deps = [
        ":config_helper",
        ":mock_emu_frontend",
        ":pw_emu",
    ],
)

pw_py_binary(
    name = "mock_emu",
    srcs = ["mock_emu.py"],
)

py_library(
    name = "config_helper",
    srcs = ["tests/config_helper.py"],
    imports = ["tests"],
    deps = ["//pw_emu/py:pw_emu"],
)

py_library(
    name = "mock_emu_frontend",
    srcs = ["mock_emu_frontend.py"],
    imports = ["."],
    deps = [
        ":pw_emu",
    ],
)
